#include "Socket.hpp"
#include "Protocols.hpp"

class TcpClient
{
public:
    TcpClient()
    {
    }
    void InIt(const uint16_t &port, const std::string &ip)
    {
        socket_.CreatSocket();
        if (!socket_.Connect(port, ip))
        {
            exit(0);
        }
    }

    std::string func1()
    {
        char op[] = {'+', '-', '*', '/','['};
        srand(time(0));
        Request req;
        req.x_ = rand() % 5;
        req.y_ = rand() % 5;
        req.op_ = op[rand() % sizeof(op)];
        std::string ret;
        req.Serialize(&ret);
        Header(&ret);
        lg.logmessage(Debug, "%d%c%d=", req.x_,req.op_,req.y_);
        return ret;
    }

    void Run()
    {
        while(true)
        {

            std::string recive_str;
            socket_.Send(socket_.ReturnSocketfd(), func1());
            socket_.Recive(socket_.ReturnSocketfd(), recive_str);
            std::cout << recive_str << std::endl;
            sleep(5);
        }
    }

private:
    Socket socket_;
};